home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.db.awt;
-
- import java.awt.Event;
- import java.awt.Image;
-
- public class DefaultDataSource implements DataSource {
- Matrix data;
- Grid view;
- boolean useDefault;
- boolean autoNumber;
- int first;
- Data defaultValue;
-
- public DefaultDataSource(Grid v) {
- this(v, false, (Data)null);
- }
-
- public DefaultDataSource(Grid v, boolean useDefaults) {
- this(v, useDefaults, (Data)null);
- }
-
- public DefaultDataSource(Grid v, boolean useDefaults, Data defaultData) {
- this.data = new Matrix();
- this.useDefault = false;
- this.autoNumber = false;
- this.setGrid(v);
- this.useDefault = useDefaults;
- if (useDefaults) {
- this.defaultValue = (Data)(defaultData != null ? defaultData : new DefaultData(this));
- }
-
- this.data.addElement(15, 1, new ImageStringData(this, " "));
- }
-
- public int rows() {
- return this.data.rows();
- }
-
- public Grid getView() {
- return this.view;
- }
-
- public int validDataRowRange(int top, int bottom) throws DataNotAvailable {
- int rows = this.data.rows();
- if (rows <= top) {
- throw new DataNotAvailable("Requested top=" + top + " but only " + rows + " available");
- } else {
- return Math.min(rows - 1, bottom);
- }
- }
-
- public void setCurrentRow(int row) throws TypeNotSupported {
- }
-
- public void doAutoNumbering(boolean an) {
- this.doAutoNumbering(an, this.first);
- }
-
- public void doAutoNumbering(boolean an, int n) {
- this.autoNumber = an;
- this.first = n;
- if (!this.useDefault && an) {
- this.useDefault = true;
- this.defaultValue = new ImageStringData(this);
- }
-
- }
-
- public void commitData() throws TypeNotSupported {
- }
-
- public void setDefaultData() {
- if (this.defaultValue == null) {
- this.setDefaultData(new DefaultData(this));
- }
-
- }
-
- public void setDefaultData(Data d) {
- this.useDefault = true;
- this.autoNumber = false;
- this.defaultValue = d;
- }
-
- public Data getDefaultData() {
- if (this.defaultValue == null) {
- throw new NullPointerException("Default data value not set");
- } else {
- return this.defaultValue;
- }
- }
-
- public void setGrid(Grid v) {
- this.view = v;
- }
-
- public boolean supportsMeta() {
- return false;
- }
-
- public void setupGrid(Grid v) throws TypeNotSupported {
- throw new TypeNotSupported("DefaultDataSource does not support meta information");
- }
-
- public Data readData(int row, int col) throws DataNotAvailable {
- return this.getData(row, col);
- }
-
- public Data getData(Coordinate coords) throws DataNotAvailable {
- return this.getData(coords.row, coords.col);
- }
-
- public Data getData(int r, int c) throws DataNotAvailable {
- try {
- return (Data)this.data.elementAt(r, c);
- } catch (NullPointerException e) {
- if (this.autoNumber) {
- int state = this.view.rowState(r + 1);
- this.defaultValue.setText(Integer.toString(r + this.first));
- if (state == 2) {
- this.defaultValue.appendChar('*');
- }
-
- return this.defaultValue;
- } else if (this.useDefault) {
- if (this.defaultValue instanceof DefaultData) {
- ((DefaultData)this.defaultValue).setRowAndCol(r, c);
- }
-
- return this.defaultValue;
- } else {
- throw e;
- }
- }
- }
-
- public void setData(Coordinate coords, Data d) throws TypeNotSupported {
- this.setData(coords.row, coords.col, d);
- }
-
- public void setData(int r, int c, Data d) throws TypeNotSupported {
- this.data.updateElement(r, c, d);
- }
-
- public String getText(Coordinate coords) throws DataNotAvailable {
- return this.getData(coords.row, coords.col).toString();
- }
-
- public boolean supports(Coordinate coords, int type) {
- return type == 1 || type == 2 || type == 3;
- }
-
- public Image getImage(Coordinate coords) throws DataNotAvailable {
- Data d = (Data)this.data.elementAt(coords.row, coords.col);
- return d.toImage();
- }
-
- public boolean handleEvent(Event e) {
- if (e.arg instanceof TableCell) {
- TableCell cell = (TableCell)e.arg;
-
- Data data;
- try {
- data = cell.getData();
- } catch (DataNotAvailable var5) {
- return false;
- }
-
- switch (e.id) {
- case 54:
- data.rollback();
- break;
- case 1005:
- try {
- data.commit();
- } catch (TypeNotSupported var4) {
- }
- }
- }
-
- return false;
- }
-
- public void handleException(int row, int col, Exception ex) {
- this.view.handleException(row, col, ex);
- }
-
- public void undeleteRow(int row) throws TypeNotSupported {
- throw new TypeNotSupported("Undelete not supported in DefaultDataSource");
- }
-
- public void deleteRow(int row) throws TypeNotSupported {
- this.data.removeRow(row);
- }
-
- public void insertRow(int row) throws TypeNotSupported {
- this.data.insertRow(row);
- }
-
- public int appendRow() throws TypeNotSupported {
- this.data.insertRow(this.data.rows());
- return this.data.rows() - 1;
- }
-
- public int rowState(int row) {
- return 0;
- }
-
- public void clear() {
- this.data.removeAllElements();
- }
-
- public void refresh() {
- }
-
- public void save() {
- }
-
- public void undoRow(int row) throws TypeNotSupported {
- }
-
- Data fetchData(int row, int col) {
- if (this.data.contains(row, col)) {
- return (Data)this.data.elementAt(row, col);
- } else {
- Data d = new ImageStringData(this);
- this.data.updateElement(row, col, d);
- return d;
- }
- }
-
- public boolean isDataEditable(int row, int col) {
- return true;
- }
-
- public int type(int row, int col) {
- return 1;
- }
-
- public void rollbackCurrentData() {
- }
-
- public void rollback(int row, int col) {
- }
-
- public void commit(int row, int col) {
- }
-
- public boolean isMasked(int row, int col) {
- return false;
- }
-
- public String getMask(int row, int col) throws TypeNotSupported {
- throw new TypeNotSupported();
- }
-
- public boolean supportsChoice(int row, int col) {
- return false;
- }
-
- public Data[] getChoices(int row, int col) throws TypeNotSupported {
- throw new TypeNotSupported();
- }
-
- public void setText(int row, int col, String t) {
- this.fetchData(row, col).setText(t);
- }
-
- public void insertChar(int row, int col, int pos, char c) {
- this.fetchData(row, col).insertChar(pos, c);
- }
-
- public void setText(int row, int col, char c) {
- this.fetchData(row, col).setText(c);
- }
-
- public void appendChar(int row, int col, char c) {
- this.fetchData(row, col).appendChar(c);
- }
-
- public void clearText(int row, int col) {
- if (this.data.contains(row, col)) {
- ((Data)this.data.elementAt(row, col)).clearText();
- }
-
- }
-
- public void deleteChar(int row, int col, int pos) {
- if (this.data.contains(row, col)) {
- ((Data)this.data.elementAt(row, col)).deleteChar(pos);
- }
-
- }
-
- public String subString(int row, int col, int spos, int epos) {
- if (this.data.contains(row, col)) {
- return ((Data)this.data.elementAt(row, col)).subString(spos, epos);
- } else {
- throw new StringIndexOutOfBoundsException();
- }
- }
-
- public void setImage(int row, int col, Image i) {
- this.fetchData(row, col).setImage(i);
- }
-
- public String toString(int row, int col) {
- return this.data.contains(row, col) ? ((Data)this.data.elementAt(row, col)).toString() : "";
- }
-
- public Image toImage(int row, int col) {
- return this.data.contains(row, col) ? ((Data)this.data.elementAt(row, col)).toImage() : null;
- }
- }
-